package com.game.config.primitive;

import com.game.config.XMLConfig;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * Created by legend9999 on 2016/7/4.
 */
@Component
@Root(name = "config")
public class PrimitiveConfig extends XMLConfig {
	private Logger logger = LoggerFactory.getLogger(PrimitiveConfig.class);
	@Element(name = "frameRate")
	private int frameRate;
	@Element(name = "readyTime")
	private int readyTime;
	@Element(name = "fightTime")
	private int fightTime;
	@Element(name = "endTime")
	private int endTime;
	private static PrimitiveConfig instance;

	@PostConstruct
	public void init() {
		try {
			logger.info("load PrimitiveConfig");
			instance = serializer.read(this.getClass(), this.getFile());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static PrimitiveConfig getInstance() {
		return instance;
	}

	public static void main(String[] args) {
		/*GameServerConfig gameServerConfig = new GameServerConfig();
		List<GameServer> roomList = new ArrayList<GameServer>();
		GameServer gs = new GameServer();
		gs.setIp("fdsa");
		gs.setPort(121);
		gs.setGameName("fdsa");
		gs.setGameId(1);
		roomList.add(gs);
		roomList.add(gs);
		roomList.add(gs);
		roomList.add(gs);
		roomList.add(gs);
		roomList.add(gs);
		RedisServer rs = new RedisServer();
		rs.setIp("32131");
		rs.setPort(342);
		MysqlServer ms = new MysqlServer();
		ms.setIp("fdsa");
		ms.setPort(342);
		ms.setPassowrd("fdsa");
		ms.setUsername("432");
		gameServerConfig.roomList = roomList;
		gameServerConfig.redisServer = rs;
		gameServerConfig.mysqlServer = ms;
		Serializer serializer = new Persister();
		try {
			serializer.write(gameServerConfig, gameServerConfig.getFile());
			GameServerConfig read = serializer.read(GameServerConfig.class, gameServerConfig.getFile());
			System.out.println();
		} catch (Exception e) {
			e.printStackTrace();
		}*/
		ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");
		PrimitiveConfig instance = PrimitiveConfig.getInstance();
		System.out.println();
	}

	public int getReadyTime() {
		return readyTime;
	}

	public int getFightTime() {
		return fightTime;
	}

	public int getEndTime() {
		return endTime;
	}

	protected String getDic() {
		return "primitive";
	}

	protected String getFileName() {
		return "primitiveMain";
	}

	public int getFrameRate() {
		return frameRate;
	}

}
